package Operation;

import Book.Book;
import Book.BookList;

import java.util.Scanner;

/**
 * Description:
 * Date: 2025-10-18
 * Time: 18:58
 */
public class AddBook implements IOperation{
    public void work(BookList bookList) {
        System.out.println("新增图书！！！");

        int current = bookList.getCurrentSize();
        if(current == bookList.getFullSize()){
            System.out.println("书架以满，不能新增图书！！！");
            return;
        }


        System.out.print("请输入图书名：");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();

        System.out.println("请输入作者");
        String author = scanner.nextLine();

        System.out.println("请输入类型：");
        String type = scanner.nextLine();

        System.out.println("请输入价格：");
        double price = scanner.nextDouble();

        for (int i = 0; i < current; i++) {
            Book book = bookList.getBooks(i);
            if(book.getName().equals(name)){
                System.out.println("当前书籍以存在，请勿重复新增！！！");
                return;
            }
        }

         Book book = new Book(name,author,type,price);
         bookList.setBooks(book,current);
         bookList.setCurrentSize(current+1);

        System.out.println("新增图书成功！！！");

    }
}
